home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 2.4 KB | 71 lines | [TEXT/MPS ] |
- /*
- File: TArbitratorExample2.cp
-
- Contains: This module show an example use of the TArbitrator class. It is the
- same as TArbitratorExample1.cp except it uses the GlobalArbitrator.
-
- Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #include "TInitSLM.h" // the TInitSLM class and SLM include files
-
- ///————————————————————————————————————————————————————————————————————————————————————
- /// CONSTANTS
- ///————————————————————————————————————————————————————————————————————————————————————
-
- // id of the object we register with the arbitrator
- #define kLinkObjectID "slm:exam$link1"
-
- /*————————————————————————————————————————————————————————————————————————————————————
- main
-
- This is a simple demonstration of how to use the TArbitrator class. Here we are
- going to register our object with the global arbitrator. This make it easier
- for other clients to have access to our object since they automatically have
- access to the global arbitrator. Off course they still need to know the object's ID.
- ————————————————————————————————————————————————————————————————————————————————————*/
-
- main()
- {
- TInitSLM initLibraryManager; // initialize the shared library manager
-
- if( initLibraryManager.Failed() ) // If we failed, let's go home
- return 1;
-
- TArbitrator *gArbitrator;
-
- if( gArbitrator = GetGlobalArbitrator() ) { // get a pointer to Global Arbitrator
-
- cout << "Got a pointer to the global arbitrator" << endl;
-
- TLink *link;
-
- if( link = new TLink ) { // This is the object we are arbitrating
-
- cout <<"Allocating and registering an object…" << endl;
-
- // Register the object so other clients can look it up
- OSErr err = gArbitrator->RegisterObject( kLinkObjectID, (void *)link );
- if( err != kNoError)
- cout << "ERROR ==> {RegisterObject} = " << err << endl;
- else {
- // see if we can find the object by ID
- TLink *object = (TLink *)gArbitrator->LookupObject( kLinkObjectID );
-
- if( object != link ) // if object returned != our object
- cout << "Something fishy, we got a wrong object" << endl;
- else
- cout << "LookupObject returned our Registered object" << endl;
-
- // since we are the only one using this object we can go ahead
- // unregister and then delete the object
- if( object = (TLink *)gArbitrator->UnregisterObject( kLinkObjectID ) )
- cout << "Unregistered the object OK" << endl;
- }
- delete link; // we are done w/ the object
- }
- }
- return 0;
- }
-